/**   
* @Package com.app.open.sys.application.service 
*/
package com.wlyy.bcwlw.sys.application.service;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.wlyy.bcwlw.sys.application.dao.ApplicationDAO;
import com.wlyy.bcwlw.sys.application.entity.ApplicationDTO;
import com.wlyy.bcwlw.sys.menu.dao.ModuleDAO;
import com.wlyy.bcwlw.sys.menu.entity.ModuleDTO;


@Transactional
@Service
public class ApplicationService {
	@Autowired
	private ApplicationDAO applicationDAO;
	@Autowired
	private ModuleDAO moduleDAO;
	
	/**
	 * 
	* @Title. getAllApp
	* @Description. 获取所有应用
	* @return List<ApplicationDTO>
	* @exception.
	 */
	public List<ApplicationDTO> getAllApp(){
		return applicationDAO.queryListByCriteria(null, "sort asc", null, null);
	}
	
	
	public boolean saveApplicationInfo(ApplicationDTO applicationDTO){
		if(StringUtils.isEmpty(applicationDTO.getAppId())){
			applicationDAO.create(applicationDTO);
		}else{
			applicationDAO.update(applicationDTO);
		}
		return true;
	}
	
	
	public boolean removeAppByAppId(String appId){
		if(StringUtils.isEmpty(appId)){
			return false;
		}
		ModuleDTO  moduleDTO = new ModuleDTO();
		moduleDTO.setAppId(appId);
		int count = moduleDAO.count(moduleDTO);
		if(count >0){
			return false;
		}
		applicationDAO.removeById(appId);
		return true;
	}
	
	
	

}
